<?php
/**
 * Copyright (C), 2021-2021, Shall Buy Life info. Co., Ltd.
 * FileName: Decoration.php
 * Description: 说明
 *
 * @author lwl
 * @Create Date    2021/11/26 16:15
 * @Update Date    2021/11/26 16:15 By lwl
 * @version v1.0
 */

namespace Example\Services\Processor\Order;

use Illuminate\Http\Response;
use YiluTech\YiMQ\Processor\TccProcessor;

class OrderCreate extends TccProcessor
{
//    public $childTransactionTopic = 'air.order.tcc.create';
    /**
     * FunctionName：validate
     * Description：
     * Author：lwl
     * @param $validator
     * @return array
     */
    protected function validate($validator)
    {
        return [];
    }

    /**
     * FunctionName：try
     * Description：
     * Author：lwl
     * @return array|false[]
     */
    public function try()
    {
        $result = OrderService::getInstance()->try($this->data);
        if ($result['code'] != Response::HTTP_OK) {
            return ['result' => false];
        }
        return ['result' => true];
    }

    /**
     * FunctionName：cancel
     * Description：
     * Author：lwl
     * @return bool[]|false[]
     */
    public function cancel()
    {
        $order = $this->processModel['try_result'];
        if ($order['result']) {
            $result = OrderService::getInstance()->cancel($order['order_sn']);
            if ($result['code'] != Response::HTTP_OK) {
                return ['result' => false];
            }
            return ['result' => true];
        }
        return ['result' => false];
    }

    /**
     * FunctionName：confirm
     * Description：
     * Author：lwl
     * @return false[]|void
     */
    public function confirm()
    {
        $order = $this->processModel['try_result'];
        if ($order['result']) {
            $result = OrderService::getInstance()->confirm($order['order_sn']);
            if ($result['code'] != Response::HTTP_OK) {
                return ['result' => false];
            }
            return ['result' => true];
        }
        return ['result' => false];
    }
}
